﻿using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.IdentityModel.Tokens.Jwt;
using System.Linq;
using System.Security.Claims;
using System.Text;
using System.Threading.Tasks;
using IM.Easy.Core.Extensions;
using IM.Easy.Core.Configuration;
using Microsoft.Extensions.Configuration;
using IM.Easy.Core.Log;

namespace IM.Easy.Core.AppContext
{
    /// <summary>
    /// 系统静态类
    /// </summary>
    public static class ImApp
    {
        internal static void Configure(IHttpContextAccessor accessor)
        {
            _accessor = accessor;
        }

        private static IHttpContextAccessor _accessor;
        public static HttpContext Current => _accessor?.HttpContext;

        public static IConfigManager Configuration => ConfigManager.Instance;

        public static IUserContext User => GetService<IUserContext>();


        public static TService GetService<TService>() where TService : class
        {
            var service = Current?.RequestServices.GetService(typeof(TService)) as TService;
            return service;
        }
    }
}
